# -*- coding:utf-8 -*-
__author__ = 'xigu007'
from kivy.clock import Clock
from pulldrawerview import PullDrawerView

class FloatLayerScrollView(PullDrawerView):

    def __init__(self,**kwargs):
        self.register_event_type('on_scrolling')
        self.register_event_type('on_layout')
        self.trigger_layout = Clock.create_trigger(self.layout_float_layer, -1)
        super(FloatLayerScrollView, self).__init__(**kwargs)


    def add_widget_background(self, widget):
        self.add_widget(widget, len(self.children))
        self.trigger_layout()

    def add_widget_foreground(self, widget):
        self.add_widget(widget)
        self.trigger_layout()

    def layout_float_layer(self, dt):
        self.dispatch('on_layout', self.x, self.y, self.width, self.height)

    def _scrolling(self, instance, value):
        sv = self._scroll_view
        effect_y = sv.effect_y
        self.dispatch('on_scrolling', value, effect_y.min, effect_y.max, sv)

    def on_scrolling(self, scroll, min, max, rv):
        pass

    def on_layout(self,*args):
        pass

    def on_pos(self,instance,value):
        self.trigger_layout()
        super(FloatLayerScrollView,self).on_pos(instance,value)


    def on_size(self,instance,value):
        self.trigger_layout()
        super(FloatLayerScrollView,self).on_size(instance,value)


